package com.matt.controller.pad.photo;

import com.matt.commons.page.PagerQuery;
import com.matt.domain.photoalbum.PhotoAlbumStatic;
import com.matt.commons.dto.sso.AreaDTO;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.commons.model.StatusResponse;
import com.matt.service.Photo.PhotoAlbumStaticPageService;
import com.matt.service.remoteCall.SsoCallService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.matt.foundation.constant.RequestConstant.TICKET;

@RestController
@RequestMapping("/pad/static_photo_album")
@Slf4j
public class PadPhotoAlbumStaticPageController {

    @Autowired
    private PhotoAlbumStaticPageService photoAlbumService;

    @Autowired
    private MemVerificationCache cache;

    @Autowired
    private SsoCallService ssoCallService;

    @RequestMapping(value = "/albums", method = RequestMethod.GET)
    public StatusResponse childrenAlbumPage(@RequestHeader(TICKET) String ticket, String childrenId, PagerQuery pagerQuery ){
        String areaId = cache.getStaff(ticket).getAreaId();
        Page<PhotoAlbumStatic> page = photoAlbumService.childrenAlbumPage(childrenId, areaId, pagerQuery);
        return StatusResponse.success(page);
    }

    @RequestMapping(value = "/request_print", method = RequestMethod.GET)
    public StatusResponse requestPrint(@RequestHeader(TICKET) String ticket, String albumId ){
        String areaId = cache.getStaff(ticket).getAreaId();
        PhotoAlbumStatic album = photoAlbumService.requestPrintAlbum(areaId, albumId);
        return StatusResponse.success(album);
    }

    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public StatusResponse albumDetail(@RequestHeader(TICKET) String ticket, String albumId ){
        AreaDTO area = ssoCallService.getAreaDTO(ticket);
        PhotoAlbumStatic album = photoAlbumService.photoAlbumById(area.getId(), albumId);
        return StatusResponse.success(album);
    }

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public StatusResponse createAlbum(@RequestHeader(TICKET) String ticket, String childrenId, String jsonStr){
        AreaDTO area = ssoCallService.getAreaDTO(ticket);

        PhotoAlbumStatic album = photoAlbumService.createPhotoAlbum(childrenId, area.getId(), area.getName(),jsonStr);
        return StatusResponse.success(album);
    }

    @RequestMapping(value = "/all_valid_photos", method = RequestMethod.GET)
    public StatusResponse addLiveRecord(@RequestHeader(TICKET) String ticket, String childrenId, PagerQuery pagerQuery ){
        String areaId = cache.getStaff(ticket).getAreaId();
        Page<String> phtotos = photoAlbumService.getAllValidPhotoURL(childrenId, areaId, pagerQuery);
        return StatusResponse.success(phtotos);
    }

    @RequestMapping(value = "/album_templates", method = RequestMethod.GET)
    public StatusResponse getAlbumTemplates(@RequestHeader(TICKET) String ticket, PagerQuery pagerQuery ){
        String areaId = cache.getStaff(ticket).getAreaId();
        List templates = photoAlbumService.getAllTemplates(areaId);
        return StatusResponse.success(templates);
    }

    @RequestMapping(value = "/album_template_pages", method = RequestMethod.GET)
    public StatusResponse getAlbumTemplatePages(@RequestHeader(TICKET) String ticket, String templateId ){
        String areaId = cache.getStaff(ticket).getAreaId();
        List pages = photoAlbumService.getAllTemplatePages(templateId);
        return StatusResponse.success(pages);
    }
}
